#include "ThreadPool.hpp"
#include "Task.hpp"
#include <ctime>

pthread_spinlock_t slock;//自旋锁

int main()
{
    // pthread_spin_init(&slock,0);
    // pthread_spin_destroy(&slock);

    // ThreadPool<Task>* tp = new ThreadPool<Task>(5);
    // tp->Start();

    //如果获取单例对象的时候，也是多线程获取的呢？

    cout<<"process running..."<<endl;
    ThreadPool<Task>::GetInstance()->Start();
    srand(time(nullptr)^getpid());
    while(true)
    {
        //1.构建任务
        int data1 = rand() % 10 + 1;
        usleep(10);
        int data2=rand()%5;
        char op=opers[rand()%opers.size()];

        Task t(data1,data2,op);
        // tp->Push(t);
        ThreadPool<Task>::GetInstance()->Push(t);
        //2.交给线程池处理
        cout<<"main thread make task: "<<t.GetTask()<<endl;

        sleep(1);
    }


    return 0;
}